/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 98152
 * Date: 2024-07-12
 * Time: 9:59
 */
public class MyQueue {

    static class ListNode {
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode first = null;
    public ListNode last = null;

    public int usedSize = 0;

    public void offer(int val) {
        ListNode node = new ListNode(val);
        if(first == null) {
            first = last = node;
        }else {
            node.prev = last;
            last.next = node;
            last = node;
        }
        usedSize++;
    }

    public int poll() {
        if(first == null) {
            return -1;
        } else {
            int ret = first.val;
            first = first.next;
            if(first != null){
                first.prev = null;
            }
            usedSize--;
            return ret;
        }
    }

    public int peek() {
        if(first == null) {
            return -1;
        } else {
            return first.val;
        }
    }

    public boolean isEmpty() {
        return usedSize == 0;
    }
}
